package com.shopping.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shopping.service.OrderGoodsService;
import com.shopping.service.ShopCarService;
import com.shopping.service.impl.OrderGoodsServiceImpl;
import com.shopping.service.impl.ShopCarServiceImpl;

/**
 * @author 2165435274
 *此为添加订单
 *依靠数组添加至数据库
 */
@WebServlet("/balance.do")
public class BalanceServlet extends HttpServlet {
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		Map<String,String[]> map = req.getParameterMap();
		OrderGoodsService ogs = new OrderGoodsServiceImpl();
		ShopCarService scs = new ShopCarServiceImpl();
		
		int num = ogs.insertOrder(map);
		if(num ==1) {
			scs.delGoods(map);
		}
		req.setAttribute("userId", map.get("userId")[0]);
		req.getRequestDispatcher("FindOrder.do").forward(req, resp);
		
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req,resp);
	}

}
